﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style type="text/css">
html {
	height: 100%
}

body {
	height: 100%;
	margin: 0px;
	padding: 0px
}

#container {
	height: 90%
}
</style>
<script type="text/javascript" src="http://api.map.baidu.com/api?v=1.3"></script>
<script type="text/javascript" src="../../resource/js/jquery.1.9.1.js"></script>
</head>
<body>
<?php
require("../php/connection.php"); ?>
<?php 
session_start();
$user_id = $_SESSION['user_id'];
$query = "SELECT * FROM map where user_id= $user_id";
$result = mysql_query($query) or die("Query failed");
$row = mysql_fetch_row($result);
?>
	<div id="container">
	</div>
	<div>
	<form action='../php/update_map.php' method='post'>
		<input type='hidden' id='lat' name='lat' value="<?php echo $row[2] ?>"/>
		<input type='hidden' id='lgt' name='lgt'  value="<?php echo $row[3] ?>" />
		<input type="text" name="info" value="<?php echo $row[4]?>" />
		<input type='submit' value='保存'/><input type='button' value='取消'onclick="window.location.href='map.php';" />
	</form>
	</div>
	<script type="text/javascript">
	var sContent ="<h1>" + "<?php echo $row[4] ?>"+ "</h1>";
	var infoWindow = new BMap.InfoWindow(sContent); // 创建信息窗口对象
		var map = new BMap.Map("container"); // 创建地图实例
		var lat = <?php echo $row[2] ?>;
		var lng = <?php echo $row[3] ?>;
		var point = new BMap.Point(lng, lat); // 创建点坐标
		map.centerAndZoom(point, 14); // 初始化地图，设置中心点坐标和地图级别
		map.addControl(new BMap.NavigationControl());
		map.addControl(new BMap.ScaleControl());
		map.addControl(new BMap.OverviewMapControl());
		map.addControl(new BMap.MapTypeControl());
		map.enableScrollWheelZoom();
		var marker = new BMap.Marker(point); // 创建标注  
		marker.addEventListener("click", function() {
			this.openInfoWindow(infoWindow);
			//图片加载完毕重绘infowindow
		});
		map.addOverlay(marker);
		map.addEventListener("rightclick", function(e){
			  	var tempPoint = new BMap.Point( e.point.lng , e.point.lat);
				var tempMarker = new BMap.Marker(tempPoint);  // 创建信息窗口对象  
				tempMarker.addEventListener("click", function() {
					this.openInfoWindow(infoWindow);
					//图片加载完毕重绘infowindow
				});
				this.addOverlay(tempMarker); 
				map.removeOverlay(marker);
				marker= tempMarker;
				$("#lat").val(e.point.lat);
				$("#lgt").val(e.point.lng);	 
			});
	</script>
</html>